<%@page import="java.util.Map"%>
<%@ page contentType="text/html; charset=utf-8" language="java" import="java.sql.*" errorPage=""%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
		<title>网络在线考试――后台管理</title>
		<link href="<%=request.getContextPath() %>/CSS/style.css" rel="stylesheet"></link>
		
		<script type="text/javascript">
			function imgPreview(fileDom)
			{
				alert("触发预览");
				//判断是否支持FileReader
				if(window.FileReader)
				{
					var reader = new FileReader();
				}
				else
				{
					alert("您的设备不支持图片预览功能，如需该功能请升级您的设备!");
				}
				//获取文件
				var file = fileDom.files[0];//通过js的组合选择器获取到页面中的第一个文件域
				var imageType = /^image\//;//图片的正则表达式
				//验证是否是图片
				if(!imageType.test(file.type))
				{
					alert("请选择图片!")
					document.getElementById("spid").innerHTML="<input type=\"file\" name=\"image\" onchange=\"imgPreview(this)\" accept=\"image/gif,image/jpeg,image/jpg,image/png,image/svg\" />";
					alert("清空刚刚选择的非图片的文件了.....");
					return false;
				}
				//读取完成
				reader.onload = function(e)
				{
					//获取图片dom
					var img = document.getElementById("preview");
					//图片路径设置为读取的图片
					alert(e.target.result)
					img.src = e.target.result;
				};
				reader.readAsDataURL(file);
			}
			
			function checkForm(form)
			{
				var imageFileValue = form["image"].value;
				alert("imageFileValue:"+imageFileValue);
				if(imageFileValue=="")
				{
					alert("请选择用户头像...")
					return false;
				}
				alert("2.图片的大小验证");
				var imgFileElement = document.getElementById("imgFile");
				var fileData = imgFileElement.files[0];
				var size = fileData.size;
				alert("size:"+size);
				if(size>1024*1024)
				{
					alert("您本次上传的图片超过1MB了，请选择一个小点的再上传...");
					return false;
				}
			}
		</script>
	</head>
	<body>
	
		<%@ include file="/manage/top.jsp"%>
		
		<table width="960" border="0" align="center" cellspacing="0" cellpadding="0">
			<tr>
				<td width="176" align="center" valign="top" bgcolor="#FFFFFF">
				
					<%@ include file="/manage/left.jsp"%>
					
				</td>
				<td align="right" valign="top" bgcolor="#FFFFFF">
					<table width="99%" border="0" cellpadding="0" cellspacing="0" align="center">
						<tr>
							<td height="30" bgcolor="#EEEEEE" class="tableBorder_thin">
								<table width="100%" border="0" cellspacing="0" cellpadding="0">
									<tr>
										<td width="78%" class="word_grey" align="left">
											&nbsp;当前位置：<span class="word_darkGrey">管理员信息管理 &gt;&gt;添加管理员&gt;&gt;</span>
										</td>
										<td align="right">
											<img src="<%=request.getContextPath() %>/Images/m_ico1.gif" width="5" height="9">&nbsp;
											当前管理员：<%=((Map)session.getAttribute("user")).get("manager_name")%>&nbsp;
										</td>
									</tr>
								</table></td>
						</tr>
						<tr>
							<td align="center" valign="top">
								<table width="100%"  border="0" cellspacing="0" cellpadding="0">
									<tr>
								   		<td width="84%">&nbsp;      </td>
									</tr>
								</table> 
								
								<form name="form1" method="post" action="<%=request.getContextPath() %>/manage/manager.do?method=add" onsubmit="return checkForm(form1)" enctype="multipart/form-data">
									<table border="2px" bordercolor="green"  align="center">
							         <tr>
							           <td>管理员名字：</td>
							           <td><input type="text"  name="manager_name"  value=""/></td>
							           <td rowspan="3"><img id="preview"   style="width:130px;height:130px"  src="<%=request.getContextPath()%>/Images/dp.png"  /></td>
							         </tr>
							         
							          <tr>
							           <td>管理员密码：</td>
							           <td><input type="text"  name="manager_pass"  value=""/></td>
							         </tr>
							         
							         <tr>
							         <td>管理员头像：</td>
							          <td> <span id="spid"><input   type="file"   name="image"  onchange="imgPreview(this)"   id="imgFile"/></span></td>
							         </tr>
							         <tr>
							           <td colspan="3"><input  style="float: right" type="submit" value="提交"/></td>
							         </tr>
							        </table>
								</form>
							</td>
						</tr>
					</table></td>
			</tr>
		</table>
		<%@ include file="/manage/copyright.jsp"%>
	</body>
</html>
